<template>
  <div class="records">
    <el-timeline :reverse="reverse">
      <el-timeline-item v-for="(item, index) in track"
                        :key="index"
                        :timestamp="item.timestamp"
                        class="con-left">
        <div class="date width">
          <span>{{item.date}}</span>
        </div>
      </el-timeline-item>
    </el-timeline>
    <div v-show="!track.length"
         class="empty">暂无数据</div>
  </div>
</template>

<script>
import { track } from "@/api/index";
export default {
  name: 'Record',
  props: {
    value: {
      type: Object,
      default: () => { }
    },
    trackType: {
      type: String,
      default: () => ''
    },
    tenantId: {
      type: [Number, String],
      default: () => ''
    }
  },
  data () {
    return {
      reverse: false,
      track: []
    };
  },
  computed: {
    trackId () {
      return this.value?.consigneeId
    },
    values () {
      return this.value
    }
  },
  watch: {
    values: {
      handler () {
        this.selectRecord()
      }
    }
  },
  mounted () {
    this.selectRecord()
  },
  methods: {
    async selectRecord () {
      if (!this.trackId) return
      let { data } = await track.information(this.trackId, this.trackType);
      data.map(item => {
        item.timestamp = item.message.slice(item.message.lastIndexOf('】') + 1)
        item.date = item.message.slice(0, item.message.lastIndexOf('】') + 1)
      })
      this.track = data
    }
  }
}
</script>

<style scoped lang="scss">
.records {
  padding: 10px 0px 0px 30px;
  margin: 10px 0px;
  max-height: 400px;
  overflow-y: auto;
}
.records >>> .el-timeline-item__wrapper {
  top: -12px;
}
.records >>> .el-timeline-item__node {
  background-color: #ffdbc4;
}
/deep/ .el-timeline-item__timestamp {
  line-height: 18px;
}
.date {
  color: var(--prev-color-text-black);
  font-size: 16px;
  line-height: 23px;
}
.cont {
  white-space: normal;
  text-overflow: ellipsis;
  color: #686868;
  font-size: 14px;
  line-height: 20px;
}
.width {
  width: 95% !important;
  word-break: break-all;
}
.empty {
  margin: 10px 0px;
  text-align: center;
  font-size: 16px;
}
</style>